package com.fs.iot.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fs.common.base.service.AbstractBaseEntityService;
import com.fs.iot.bean.dto.DeviceCategoryDTO;
import com.fs.iot.bean.query.DeviceCategoryQuery;
import com.fs.iot.domain.entity.DeviceCategoryEntity;
import com.fs.iot.domain.mapper.DeviceCategoryMapper;
import com.fs.iot.service.DeviceCategoryEntityService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

/**
 * 设备分类服务实现 
 * @author Coder Generator 2025-03-22 15:14:00 
 **/
@Service
public class DeviceCategoryEntityServiceImpl extends AbstractBaseEntityService<DeviceCategoryEntity, DeviceCategoryDTO, DeviceCategoryMapper, DeviceCategoryQuery> implements DeviceCategoryEntityService {
    @Override
    public DeviceCategoryDTO toDTO(DeviceCategoryEntity entity) {
        DeviceCategoryDTO dto = new DeviceCategoryDTO();
        BeanUtils.copyProperties(entity, dto);
        return dto;
    }

    @Override
    public DeviceCategoryEntity toEntity(DeviceCategoryDTO dto) {
        DeviceCategoryEntity entity = new DeviceCategoryEntity();
        BeanUtils.copyProperties(dto, entity);
        return entity;
    }

    @Override
    protected QueryWrapper<DeviceCategoryEntity> queryToWrapper(DeviceCategoryQuery query) {
        return this.createQueryWrapper()
                .eq(StringUtils.isNotBlank(query.getId()), "id", query.getId())
                .in(null != query.getIds(), "id", query.getIds())
                .eq(StringUtils.isNotBlank(query.getName()), "name", query.getName())
                .eq(StringUtils.isNotBlank(query.getParentId()), "parent_id", query.getParentId())
                .orderByDesc("create_time");
    }
}